import redis


def t_conn(host, port, password):
    r = redis.Redis(host=host, port=port, password=password)
    if r.ping():
        print("redis连接成功......\n")
        if r.exists("test"):
            print("-" * 5 + "打印test" + "-" * 5)
            print("test：{0}".format(r.get("test")))
        else:
            print("测试数据不存在")
            print("插入键值对test:1234......")
            r.set("test", "1234")
            print("-" * 5 + "如果插入成功就会有值出现" + "-" * 5)
            print("test：{0}".format(r.get("test")))
            print("")
            print("删除key test......")
            r.delete("test")
            print("-" * 5 + "打印test" + "-" * 5)
            print("test：{0}".format(r.get("test")))
    else:
        print("redis连接失败......")


# t_conn("139.224.70.66", 6379, "SSDEFE#@^&&N89Enet@#DW#S")
t_conn(input("输入redis服务器地址："), input("输入连接端口："), input("输入连接密码："))